package com.rachel.materialdemo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.rachel.materialdemo.R;
import com.rachel.materialdemo.ToolUtils;
import com.rachel.materialdemo.bean.HomeBean;

import java.util.List;

public class LBaseAdapter extends BaseAdapter {
	private static final String TAG = "zsr";
	private Context mContext;
	private List<HomeBean> mList;


	public LBaseAdapter(Context context, List<HomeBean> list){
		
		mContext = context;
		mList = list;

	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}
	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mList.get(arg0);
	}
	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public int getItemViewType(int position) {
		return mList.get(position).type;
	}

	@Override
	public int getViewTypeCount() {
		return ToolUtils.TYPE_COUNT;
	}



	@Override
	public View getView(int position, View contentView, ViewGroup parent) {


		int viewtype = getItemViewType(position);
		HomeBean bean = mList.get(position);

		LBaseViewholder viewholder = null;
		switch (viewtype){
			case ToolUtils.TYPE_ONE:

				viewholder = LBaseViewholder.getLBaseViewholder(mContext,
						contentView,R.layout.cardview_item,parent,position);
				viewholder.setText(R.id.card_text, bean.title);
				viewholder.setDrawable(R.id.card_img,bean.resid);
			break;
			case ToolUtils.TYPE_TWO:
				viewholder = LBaseViewholder.getLBaseViewholder(mContext,
						contentView,R.layout.cardview_item_two,parent,position);
				viewholder.setText(R.id.card_text_one, bean.title)
						.setText(R.id.card_text_two,bean.title)
						.setDrawable(R.id.card_img_one,bean.resid)
						.setDrawable(R.id.card_img_two,bean.residtwo);

				break;
		}
		return viewholder.getConverView();
		
	}	
}